﻿#ifndef __AVOID_CONTROL_INTERFACE_USER_DRAW_HEAD_FILE_INCLUEDD__
#define __AVOID_CONTROL_INTERFACE_USER_DRAW_HEAD_FILE_INCLUEDD__
#include "../control.h"

namespace swui
{
	struct ctlNotifyUserDraw
	{
		/* 通常情况下，background 是在文字绘制之前，背景绘制之后
		 * foreground 是在文字绘制之后
		 * 如果控件不会绘制文字并且有 IBackground 接口
		 * 那么 background 则是在 IBackground 绘制前
		 * foreground 是在 IBackground 绘制之后 */
		enum { background, foreground } state;
		void* graphics;		// 这个指针可以被转换为 Gdiplus::Graphics*
		void* hDC;
	};

	class IUserDraw : virtual public ctlRoot
	{
	public:
		IUserDraw() : _userdraw_enable(false) {}
		void enableUserDraw(bool = true);
		bool isUserDrawEnabled();
	protected:
		void _notify_draw_event_(_ctlInterior::drawInfo*, bool back);
	private:
		bool _userdraw_enable;
	};

	inline void IUserDraw::enableUserDraw(bool b)
	{
		_userdraw_enable = b;
		redraw();
	}
	inline bool IUserDraw::isUserDrawEnabled()
	{
		return _userdraw_enable;
	}
	inline void IUserDraw::_notify_draw_event_(_ctlInterior::drawInfo* info, bool back)
	{
		ctlNotifyEvent ne;
		ne.eventType = ctlNotifyEventType::draw;
		ctlNotifyUserDraw nud;
		nud.state = back ? ctlNotifyUserDraw::background : 
			ctlNotifyUserDraw::foreground;
		nud.graphics = info->graphics;
		nud.hDC = info->hDC;
		ne.info = &nud;
		_notify_event_(&ne);
	}
}


#endif